# -*- coding: utf-8 -*-

'''eof
name:申请企业失信记录校验
code:R53_EG_CASE_EntLostLetterRecordCheck
tableName:
columnName:
groups:个人及企业司法校验
dependencies:EG_CASE_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

def FormatData(tableName):
    try:
        eg = EG_CASE_DSJ.get("data").get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def getRule53():
    shixin_list_nowname = FormatData("R230")
    shixin_list_oldname = FormatData("FR230")
    if shixin_list_nowname == [{}] and shixin_list_oldname == [{}]:
        return u"缺失值"
    elif shixin_list_nowname == [] and shixin_list_oldname == []:
		return 0
    else:
        duplicate_list = []
        conts = 0
        if shixin_list_nowname != [{}]:
            for i in shixin_list_nowname:
                try:
                    casecode = i.get("CASECODE")
                    if casecode not in null_type_list:
                        duplicate_list.append(casecode)
                except:
                    pass
                    conts += 1
        else:
            pass
        if shixin_list_oldname != [{}]:
            for i in shixin_list_oldname:
                try:
                    casecode = i.get("CASECODE")
                    if casecode not in null_type_list:
                        duplicate_list.append(casecode)
                except:
                    pass
                    conts += 1
        else:
            pass

        if conts == len(shixin_list_nowname) + len(shixin_list_oldname):
            return u'缺失值'
        else:
            return len(set(duplicate_list))
		
result = getRule53()

